{% extends 'base.html' %}
{% load widget_tweaks %}

{% block title %}{{ title }}{% endblock %}

{% block extra_css %}
<style>
:root {
    --primary-color: #00ffff;
    --secondary-color: #ff6b6b;
    --bg-color: #0a0a0a;
    --card-bg: #1a1a1a;
    --text-color: #ffffff;
    --border-color: #333;
    --success-color: #4ecdc4;
    --warning-color: #ffe66d;
    --error-color: #ff6b6b;
}

.form-container {
    max-width: 800px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: 15px;
    padding: 2rem;
    box-shadow: 0 10px 30px rgba(0, 255, 255, 0.1);
    border: 1px solid var(--border-color);
}

.form-title {
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 2rem;
    font-weight: 600;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    color: var(--text-color);
    font-weight: 500;
    margin-bottom: 0.5rem;
    display: block;
}

.form-control, .form-select {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    padding: 0.75rem;
    width: 100%;
    transition: all 0.3s ease;
}

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 255, 255, 0.1);
    background: var(--bg-color);
    color: var(--text-color);
}

.form-control::placeholder {
    color: #888;
}

.form-check {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

.form-check-input {
    margin-right: 0.5rem;
    accent-color: var(--primary-color);
}

.form-check-label {
    color: var(--text-color);
    cursor: pointer;
}

.help-text {
    font-size: 0.875rem;
    color: #888;
    margin-top: 0.25rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #0099cc);
    border: none;
    color: var(--bg-color);
    padding: 0.75rem 2rem;
    border-radius: 25px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 255, 255, 0.3);
    color: var(--bg-color);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.75rem 2rem;
    border-radius: 25px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    margin-right: 1rem;
}

.btn-secondary:hover {
    background: var(--border-color);
    color: var(--text-color);
}

.button-group {
    text-align: center;
    margin-top: 2rem;
}

.error-list {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    list-style: none;
    padding: 0;
}

.error-list li {
    margin-bottom: 0.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-container {
        margin: 1rem;
        padding: 1.5rem;
    }
}
</style>
{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="form-container">
        <h1 class="form-title">
            <i class="fas fa-tools"></i>
            {{ title }}
        </h1>
        
        <form method="post" enctype="multipart/form-data">
            {% csrf_token %}
            
            <div class="form-group">
                <label for="{{ form.name.id_for_label }}" class="form-label">
                    {{ form.name.label }}
                    <span class="text-danger">*</span>
                </label>
                {{ form.name|add_class:"form-control" }}
                {% if form.name.errors %}
                    <ul class="error-list">
                        {% for error in form.name.errors %}
                            <li>{{ error }}</li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </div>
            
            <div class="form-row">
                <div class="form-group">
                    <label for="{{ form.category.id_for_label }}" class="form-label">
                        {{ form.category.label }}
                    </label>
                    {{ form.category|add_class:"form-select" }}
                    {% if form.category.errors %}
                        <ul class="error-list">
                            {% for error in form.category.errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>
                
                <div class="form-group">
                    <label for="{{ form.tool_type.id_for_label }}" class="form-label">
                        {{ form.tool_type.label }}
                        <span class="text-danger">*</span>
                    </label>
                    {{ form.tool_type|add_class:"form-select" }}
                    {% if form.tool_type.errors %}
                        <ul class="error-list">
                            {% for error in form.tool_type.errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>
            </div>
            
            <div class="form-group">
                <label for="{{ form.description.id_for_label }}" class="form-label">
                    {{ form.description.label }}
                    <span class="text-danger">*</span>
                </label>
                {{ form.description|add_class:"form-control" }}
                {% if form.description.errors %}
                    <ul class="error-list">
                        {% for error in form.description.errors %}
                            <li>{{ error }}</li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </div>
            
            <div class="form-group">
                <label for="{{ form.url.id_for_label }}" class="form-label">
                    {{ form.url.label }}
                    <span class="text-danger">*</span>
                </label>
                {{ form.url|add_class:"form-control" }}
                {% if form.url.help_text %}
                    <div class="help-text">{{ form.url.help_text }}</div>
                {% endif %}
                {% if form.url.errors %}
                    <ul class="error-list">
                        {% for error in form.url.errors %}
                            <li>{{ error }}</li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </div>
            
            <div class="form-row">
                <div class="form-group">
                    <label for="{{ form.icon.id_for_label }}" class="form-label">
                        {{ form.icon.label }}
                    </label>
                    {{ form.icon|add_class:"form-control" }}
                    {% if form.icon.help_text %}
                        <div class="help-text">{{ form.icon.help_text }}</div>
                    {% endif %}
                    {% if form.icon.errors %}
                        <ul class="error-list">
                            {% for error in form.icon.errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>
                
                <div class="form-group">
                    <label for="{{ form.screenshot.id_for_label }}" class="form-label">
                        {{ form.screenshot.label }}
                    </label>
                    {{ form.screenshot|add_class:"form-control" }}
                    {% if form.screenshot.help_text %}
                        <div class="help-text">{{ form.screenshot.help_text }}</div>
                    {% endif %}
                    {% if form.screenshot.errors %}
                        <ul class="error-list">
                            {% for error in form.screenshot.errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>
            </div>
            
            <div class="form-row">
                <div class="form-group">
                    <div class="form-check">
                        {{ form.is_featured|add_class:"form-check-input" }}
                        <label for="{{ form.is_featured.id_for_label }}" class="form-check-label">
                            {{ form.is_featured.label }}
                        </label>
                    </div>
                    {% if form.is_featured.errors %}
                        <ul class="error-list">
                            {% for error in form.is_featured.errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>
                
                <div class="form-group">
                    <div class="form-check">
                        {{ form.is_free|add_class:"form-check-input" }}
                        <label for="{{ form.is_free.id_for_label }}" class="form-check-label">
                            {{ form.is_free.label }}
                        </label>
                    </div>
                    {% if form.is_free.errors %}
                        <ul class="error-list">
                            {% for error in form.is_free.errors %}
                                <li>{{ error }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>
            </div>
            
            <div class="button-group">
                <a href="{% url 'tools:tool_list' %}" class="btn-secondary">
                    <i class="fas fa-arrow-left"></i> 取消
                </a>
                <button type="submit" class="btn-primary">
                    <i class="fas fa-save"></i> {{ action }}
                </button>
            </div>
        </form>
    </div>
</div>
{% endblock %}